// import { def, isObject, keys } from "./utils";

class Observer {
  constructor(data) {
    this.walk(data);
  }

  walk(data) {
    if (isObject(data)) {
      keys(data).forEach(key => {
        this.reactive(data, key, data[key]);
      })
    }
  }

  reactive(obj, key, value) {
    const self = this;

    self.walk(value);

    const dep = new Dep();

    def(obj, key, {
      enumerable: true,
      configurable: true,
      get() {
        Dep.target && dep.add(Dep.target);
        return value;
      },
      set(v) {
        if (value !== v) {
          value = v;
          self.walk(v);
          dep.notify();
        }
      }
    })
  }
}